
<!--
 * @Descripttion: 
 * @Author: yuxi
 * @Date: 2022-09-15 14:58:04
 * @LastEditors: yuxi
 * @LastEditTime: 2023-01-10 17:14:26
-->
<template>
  <div class="map-container">
    <MiningMap :center="center" :zoom="zoom">
      <MiningTiandituLayer :ak="key" @ready="ready"></MiningTiandituLayer>
      <MiningVectorLayer :featureStyle="style" :isCluster="true">
        <MiningPoint
          v-for="(feature, fi) in features"
          :key="fi"
          :feature="feature"
        ></MiningPoint>
      </MiningVectorLayer>
    </MiningMap>
  </div>
</template>

<script>
import MiningMap from 'mining-map/Map'
import MiningTiandituLayer from 'mining-map/Layers/TiandituLayer'
import MiningVectorLayer from 'mining-map/Layers/VectorLayer'
import MiningPoint from 'mining-map/Features/Point';
import { TiandituKey,CityCoordinates } from '@/config/config.js';

import Feature from 'ol/Feature';
import Point from 'ol/geom/Point';
import { Style, Icon } from 'ol/style';
import marker from '@/assets/images/marker.png'


export default {
  name: 'ClusterFeature',
  title: '聚合图层',
  parentTitle: 'Feature',
  components: {
    MiningMap,
    MiningTiandituLayer,
    MiningVectorLayer,
    MiningPoint
  },
  data () {
    let features = []
    for(var i=0;i<20;i++) {
      let coords = CityCoordinates.BeiJing
      coords[0] = coords[0] + (Math.random() * 0.0001)
      coords[1] = coords[1] +  (Math.random() * 0.0001)

      features.push(new Feature({ 
        type: 'Point',
        geometry: new Point(coords),
        name: 'City',
      }))
    }
     
    const style = new Style({
      image: new Icon({
        anchor: [0.5, 46],
        anchorXUnits: 'fraction',
        anchorYUnits: 'pixels',
        src: marker,
      })
    })
    return {
      features,
      style,
      center: [117.730311, 35.698681],
      zoom: 5,
      key: TiandituKey,
    }
  },
  methods: {
    ready (arg) {
      console.log(arg)
    }
  }

}
</script>

<style>
body,
html {
  padding: 0;
  margin: 0;
}

.map-container {
  width: 100%;
  height: 100vh;
}
</style>